﻿/*----------------------------------------------------------------
// Copyright (C) 2016 通通优品版权所有。
// 命名空间: TongTongMall.DapperFramework.Repositories
// 类名：ProductInfoRepository
// 功能描述：N/A
// 
// 创建标识：Roc.Lee(李鹏鹏) 2017/8/25 16:54:32 TEC-ROCLEE Roc.Lee

// 修改标识：
// 修改描述：
// 
//
//----------------------------------------------------------------*/
using Dapper;
using STOWaybillMall.Core;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Dapper;
using TongTongMall.Dapper.DapperExtensions;
using TongTongMall.MallWeb.Core.Domain.Products.Model;
using TongTongMall.MallWeb.Core.IRepositories;


namespace TongTongMall.DapperFramework.Repositories
{
    public class ProductInfoRepository : TongTongMallDbContextBase<ProductInfo, long>, IProductInfoRepository
    {
        public ProductInfoRepository(IDbContextProvider<IDatabase> dbContextProvider) : base(dbContextProvider)
        {
        }


        public IList<ProductListInfoDto> GetProductList()
        {
            return (DB.Connection.Query<ProductListInfoDto, ImageInfo, ProductListInfoDto>(
                "select top 100 pb.ProductCategory as ProductCategoryID,pb.ProductName ProductName,pb.BuyLeast BuyLeast,pb.Unit Unit,p.ProductID ProductID,p.SpecPropGroupName SpecPropGroupName,p.DefaultPrice DefaultPrice,im.URI URI  from ProductBaseInfo pb join ProductInfo p on p.ProductBaseID=pb.ProductBaseID left join ImageInfo im on im.ImageID=pb.ImageID order by pb.ProductCategory",
                splitOn: "DefaultPrice",
                map: (dto, im) =>
                {
                    dto.ProductPic = im.URI;
                    return dto;
                })).ToList();
        }
    }
}
